@isTest
private class Poductivity_Allocations_Insert_Test_Clas {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        list<Opportunity> NewOpp = new list<Opportunity>();
        
        User u = new User(Lastname = 'Test', Username = 'sampleuser715643215@gmail.com', Email = 'sampleuser715643215@gmail.com', Alias = 'test1', CommunityNickname = 'sample12', TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', EmailEncodingKey = 'ISO-8859-1', ProfileId = UserInfo.getProfileId(), LanguageLocaleKey = 'en_US', ManagerId = UserInfo.getUserId());
        for(Integer i = 0; i < 200; i++ ){
            Opportunity O = new Opportunity (
                Name = 'Test Opportuniy'+ i,
                StageName = 'Follow Up Call / E-mail / Meeting',
                CloseDate = date.today() 
            );
            NewOpp.add(O);
        }

        test.startTest();
        insert NewOpp;
  
        Opportunity o = [select id, name, ownerid from Opportunity where name = :NewOpp[0].name];
        system.assertEquals(o.name, Newopp[0].name);
        
        insert u;
        User userInserted = [select id, LastName from User where id = :u.id];
        system.assertEquals(userInserted.lastname,u.lastname);
        o.ownerid = u.id;
        update o;

        o = [select id, name, ownerid,split_opportunity_pa__c from Opportunity where name = :NewOpp[1].name];
        system.assertEquals(o.name, Newopp[1].name);

        Productivity_Allocations__c pa = new Productivity_Allocations__c(
            Opportunity_Name__c = o.Id,
            Sales_Associate__c = u.Id,
            Allocation_Percentage__c = 0.0
        );      
        
        insert pa;
        o.ownerid = u.id;
        o.split_opportunity_pa__c = true;
        try
        {
            update o;
        }
        catch(Exception e){}
        test.stopTest();
    
    }

    static testMethod void myUnitTest1() {
        // TO DO: implement unit test
        opportunity o = new opportunity(name='Test', closedate=Date.today(), stagename='Closed Won');
        insert o;
        Product2[] p = [select id from product2 order by name desc limit 1];
        Pricebookentry[] pbe = [select id from pricebookentry where product2id = :p[0].id ];
        opportunitylineitem oli = new opportunitylineitem(opportunityid = o.id, quantity= 1, totalprice=10, pricebookentryid = pbe[0].id);
        insert oli;
        User u = new User(Lastname = 'Test1', Username = 'sampleuser7156432158@gmail.com', Email = 'sampleuser715643215@gmail.com8@gmail.com', Alias = 'test', CommunityNickname = 'sample', TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', EmailEncodingKey = 'ISO-8859-1', ProfileId = UserInfo.getProfileId(), LanguageLocaleKey = 'en_US', ManagerId = UserInfo.getUserId());        
                
        Productivity_Allocations__c pa = new Productivity_Allocations__c(
            Opportunity_Name__c = o.Id,
            Sales_Associate__c = u.id,
            Allocation_Percentage__c = 0.0
        );      
        
        insert pa;
    
    }

}